package com.gethb.prod.controller;
import com.gethb.prod.service.IGetKlineService;
import com.gethb.prod.service.IUserLoginService;
import com.gethb.prod.vo.*;
import com.gethb.pub.utils.ToolsUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;

@Controller
@RequestMapping("/kline")
public class KLineController {

    private HttpServletRequest request;

    // 用户获取Kline数据实现类
    @Resource(name = "getKlineService")
    private IGetKlineService iGetKlineService;

    // 用户登陆实现类
    @Resource(name = "userLoginService")
    private IUserLoginService iUserLoginService;


    @Autowired
    public void setRequest(HttpServletRequest request) {
        this.request = request;
    }

    @ResponseBody
    @GetMapping(value = "/marketData")
    public Result<MarketDataOutVo> getMarketData(KlineDataInVo inVo) {
        //
        String userId = ToolsUtils.getUserId(iUserLoginService, request);
        if (userId == null) {
            return Result.tokenInvalid();
        }
        //
        try {
            return iGetKlineService.getMarketData(inVo);
        } catch (Exception exception) {
           return Result.exception(exception.getMessage());
        }
    }

    @ResponseBody
    @GetMapping(value = "/symbols")
    public Result<ArrayList<String>> getSymbols() {
        //
        String userId = ToolsUtils.getUserId(iUserLoginService, request);
        if (userId == null) {
            return Result.tokenInvalid();
        }
        //
        ArrayList<String> symbols = new ArrayList<>();
        symbols.add("btcusdt");
        symbols.add("ethbtc");
        return Result.success(symbols);
    }
}
